$("#register").click(function(){
    var accountNumber = $("#accountName").val();
    var password = $("#password").val();
    var againPassword = $("#againPassword").val();
    var adminName = $("#adminName").val();
    var sex = $("#sex").val();
    var identity = $("#identity").val();
    var mobilephone = $("#mobilephone").val();
    var email = $("#email").val();

    var mobilephoneCheck = /^[1][3,4,5,7,8][0-9]{9}$/;
    var identityCheck =  /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if(isEmpty(accountNumber)){
        layer.msg("账号不能为空",{icon: 5});
        return;
    }
    if(isEmpty(password)){
        layer.msg("密码不能为空",{icon: 5});
        return;
    }else if(password.length<6){
        layer.msg("密码至少得6至16个字符",{icon: 5});
        return;
    }else if(password != againPassword){
        layer.msg("密码与重复密码不相同",{icon: 5});
        return;
    }
    if(isEmpty(adminName)){
        layer.msg("姓名不能为空",{icon: 5});
        return;
    }
    if(isEmpty(sex)){
        layer.msg("请选择性别",{icon: 5});
        return;
    }
    if(isEmpty(identity)){
        layer.msg("身份不能为空",{icon: 5});
        return;
    }else if(!identityCheck.test(identity)){
        layer.msg("身份证号格式不正确",{icon: 5});
        return;
    }
    if(isEmpty(mobilephone)){
        layer.msg("手机号不能为空",{icon: 5});
        return;
    }else if(!mobilephoneCheck.test(mobilephone)){
        layer.msg("手机号格式不正确",{icon: 5});
        return;
    }

    var url = "admin/register";
    postAjaxReq(url,
        {
            accountNumber : accountNumber,
            password : password,
            adminName : adminName,
            sex : sex,
            identity : identity,
            mobilephone : mobilephone,
            email : email,
            adminStatus : 2
            },
        function(res){
            var msg = res.msg;
            if (res.code == 1) {
                layer.closeAll()
                layer.msg("注册成功,即将返回登录页",{icon: 6});
                setTimeout(function () {
                    location.href = "login";
                }, 2000);
            } else {
                layer.msg(msg)
            }
        })
});

$(".buttonC").click(function () {
    location.href = "login";
});

new QRCode(document.getElementById("code"), "https://www.baidu.com");

